﻿@model Gridview
<table id="@Model.ID" cellpadding="0" cellspacing="0" width="100%" class="gridview" page-index="@Model.Page.PageIndex" page-size="@Model.Page.PageSize">
    <tr>
        @{var provider = new GridviewDataProvider();}
        @foreach (var cell in Model.Header.Cells)
        { 
            <th @MvcHtmlString.Create(cell.GetPropertiesHtml())>
                @if (cell.DataTemplate != null)
                {
                    @Html.Partial(cell.DataTemplate.TemplateName, cell)
                }
                else
                {
                    @MvcHtmlString.Create(cell.Write())
                }
            </th>
        }
    </tr>
    @if (Model.Rows.Count > 0)
    {
        foreach (var row in Model.Rows)
        {
            int index = Model.Rows.IndexOf(row);
            string trClass = index % 2 == 0 ? "" : "evenRowClass";
            row.SetProperty("class", trClass);
        <tr @MvcHtmlString.Create(row.GetPropertiesHtml())>
            @foreach (var cell in row.Cells)
            { 
                <td @MvcHtmlString.Create(cell.GetPropertiesHtml())>
                    @if (cell.DataTemplate != null)
                    {
                        @Html.Partial("DataTemplatePartials/" + cell.DataTemplate.TemplateName, new { Data = row.Data, Template = cell.DataTemplate })
                    }
                    else
                    {
                        @MvcHtmlString.Create(cell.Write(provider, row.Data))
                    }
                </td>
            }
        </tr>
        }
    }
    else
    { 
        <tr>
            <td colspan="@Model.Header.Cells.Count">
                <span class="gridview-noresult">暂无记录</span>
            </td>
        </tr>
    }
</table>
<div class="gridview-footer">
    <div class="gridview-pager-1">
        (@(Model.Page.StartNum)-@(Model.Page.EndNum)/@(Model.Page.TotalCount)) | 每页显示：
        @for (int i = 0; i < Model.Page.PageSizes.Count; i++)
        {
            int page = Model.Page.PageSizes[i];
            if (i > 0)
            { 
            <span>, </span>
            }
            if (page == Model.Page.PageSize)
            {
            <span>@page</span>
            }
            else
            { 
            <a href="javascript:void(0);" onclick="reload($('#@Model.ID').parent(), @Model.Page.PageIndex, @page)">@page</a>
            }
        }
    </div>
    <div class="gridview-pager-2">
        <a class="ui-state-default ui-corner-all" href="javascript:void(0);" onclick="reload($('#@Model.ID').parent(), 1, @Model.Page.PageSize)"">
            <span class="ui-icon ui-icon-arrowthickstop-1-w"></span>首页 </a>
        <a class="ui-state-default ui-corner-all" href="javascript:void(0);" onclick="reload($('#@Model.ID').parent(), @(Model.Page.PageIndex - 1), @Model.Page.PageSize)"">
            <span class="ui-icon ui-icon-arrowthick-1-w"></span>上一页</a>
        <a class="ui-state-default ui-corner-all" href="javascript:void(0);" onclick="reload($('#@Model.ID').parent(), @(Model.Page.PageIndex + 1), @Model.Page.PageSize)"">
            <span class="ui-icon ui-icon-arrowthick-1-e"></span>下一页</a>
        <a class="ui-state-default ui-corner-all" href="javascript:void(0);" onclick="reload($('#@Model.ID').parent(), @Model.Page.PageTotal, @Model.Page.PageSize)"">
            <span class="ui-icon ui-icon-arrowthickstop-1-e"></span>末页</a>
    </div>
    <div class="clear">
    </div>
</div>
